<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Target Fragment (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Target Fragment (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Target Fragment (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Fragments.html" rel="up" title="Fragments">
<link href="Host-Fragment.html" rel="next" title="Host Fragment">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Target-Fragment">
<div class="nav-panel">
<p>
Next: <a href="Host-Fragment.html" accesskey="n" rel="next">Host Makefile Fragments</a>, Up: <a href="Fragments.html" accesskey="u" rel="up">Makefile Fragments</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Target-Makefile-Fragments"><span>20.1 Target Makefile Fragments<a class="copiable-link" href="#Target-Makefile-Fragments"> &para;</a></span></h3>
<a class="index-entry-id" id="index-target-makefile-fragment"></a>
<a class="index-entry-id" id="index-t_002dtarget"></a>

<p>Target makefile fragments can set these Makefile variables.
</p>
<dl class="table">
<dt><a id="index-LIBGCC2_005fCFLAGS"></a><span><code class="code">LIBGCC2_CFLAGS</code><a class="copiable-link" href="#index-LIBGCC2_005fCFLAGS"> &para;</a></span></dt>
<dd><p>Compiler flags to use when compiling <samp class="file">libgcc2.c</samp>.
</p>
</dd>
<dt><a id="index-LIB2FUNCS_005fEXTRA"></a><span><code class="code">LIB2FUNCS_EXTRA</code><a class="copiable-link" href="#index-LIB2FUNCS_005fEXTRA"> &para;</a></span></dt>
<dd><p>A list of source file names to be compiled or assembled and inserted
into <samp class="file">libgcc.a</samp>.
</p>
</dd>
<dt><a id="index-CRTSTUFF_005fT_005fCFLAGS"></a><span><code class="code">CRTSTUFF_T_CFLAGS</code><a class="copiable-link" href="#index-CRTSTUFF_005fT_005fCFLAGS"> &para;</a></span></dt>
<dd><p>Special flags used when compiling <samp class="file">crtstuff.c</samp>.
See <a class="xref" href="Initialization.html">How Initialization Functions Are Handled</a>.
</p>
</dd>
<dt><a id="index-CRTSTUFF_005fT_005fCFLAGS_005fS"></a><span><code class="code">CRTSTUFF_T_CFLAGS_S</code><a class="copiable-link" href="#index-CRTSTUFF_005fT_005fCFLAGS_005fS"> &para;</a></span></dt>
<dd><p>Special flags used when compiling <samp class="file">crtstuff.c</samp> for shared
linking.  Used if you use <samp class="file">crtbeginS.o</samp> and <samp class="file">crtendS.o</samp>
in <code class="code">EXTRA-PARTS</code>.
See <a class="xref" href="Initialization.html">How Initialization Functions Are Handled</a>.
</p>
</dd>
<dt><a id="index-MULTILIB_005fOPTIONS"></a><span><code class="code">MULTILIB_OPTIONS</code><a class="copiable-link" href="#index-MULTILIB_005fOPTIONS"> &para;</a></span></dt>
<dd><p>For some targets, invoking GCC in different ways produces objects
that cannot be linked together.  For example, for some targets GCC
produces both big and little endian code.  For these targets, you must
arrange for multiple versions of <samp class="file">libgcc.a</samp> to be compiled, one for
each set of incompatible options.  When GCC invokes the linker, it
arranges to link in the right version of <samp class="file">libgcc.a</samp>, based on
the command line options used.
</p>
<p>The <code class="code">MULTILIB_OPTIONS</code> macro lists the set of options for which
special versions of <samp class="file">libgcc.a</samp> must be built.  Write options that
are mutually incompatible side by side, separated by a slash.  Write
options that may be used together separated by a space.  The build
procedure will build all combinations of compatible options.
</p>
<p>For example, if you set <code class="code">MULTILIB_OPTIONS</code> to &lsquo;<samp class="samp">m68000/m68020
msoft-float</samp>&rsquo;, <samp class="file">Makefile</samp> will build special versions of
<samp class="file">libgcc.a</samp> using the following sets of options:  <samp class="option">-m68000</samp>,
<samp class="option">-m68020</samp>, <samp class="option">-msoft-float</samp>, &lsquo;<samp class="samp">-m68000 -msoft-float</samp>&rsquo;, and
&lsquo;<samp class="samp">-m68020 -msoft-float</samp>&rsquo;.
</p>
</dd>
<dt><a id="index-MULTILIB_005fDIRNAMES"></a><span><code class="code">MULTILIB_DIRNAMES</code><a class="copiable-link" href="#index-MULTILIB_005fDIRNAMES"> &para;</a></span></dt>
<dd><p>If <code class="code">MULTILIB_OPTIONS</code> is used, this variable specifies the
directory names that should be used to hold the various libraries.
Write one element in <code class="code">MULTILIB_DIRNAMES</code> for each element in
<code class="code">MULTILIB_OPTIONS</code>.  If <code class="code">MULTILIB_DIRNAMES</code> is not used, the
default value will be <code class="code">MULTILIB_OPTIONS</code>, with all slashes treated
as spaces.
</p>
<p><code class="code">MULTILIB_DIRNAMES</code> describes the multilib directories using GCC
conventions and is applied to directories that are part of the GCC
installation.  When multilib-enabled, the compiler will add a
subdirectory of the form <var class="var">prefix</var>/<var class="var">multilib</var> before each
directory in the search path for libraries and crt files.
</p>
<p>For example, if <code class="code">MULTILIB_OPTIONS</code> is set to &lsquo;<samp class="samp">m68000/m68020
msoft-float</samp>&rsquo;, then the default value of <code class="code">MULTILIB_DIRNAMES</code> is
&lsquo;<samp class="samp">m68000 m68020 msoft-float</samp>&rsquo;.  You may specify a different value if
you desire a different set of directory names.
</p>
</dd>
<dt><a id="index-MULTILIB_005fMATCHES"></a><span><code class="code">MULTILIB_MATCHES</code><a class="copiable-link" href="#index-MULTILIB_005fMATCHES"> &para;</a></span></dt>
<dd><p>Sometimes the same option may be written in two different ways.  If an
option is listed in <code class="code">MULTILIB_OPTIONS</code>, GCC needs to know about
any synonyms.  In that case, set <code class="code">MULTILIB_MATCHES</code> to a list of
items of the form &lsquo;<samp class="samp">option=option</samp>&rsquo; to describe all relevant
synonyms.  For example, &lsquo;<samp class="samp">m68000=mc68000 m68020=mc68020</samp>&rsquo;.
</p>
</dd>
<dt><a id="index-MULTILIB_005fEXCEPTIONS"></a><span><code class="code">MULTILIB_EXCEPTIONS</code><a class="copiable-link" href="#index-MULTILIB_005fEXCEPTIONS"> &para;</a></span></dt>
<dd><p>Sometimes when there are multiple sets of <code class="code">MULTILIB_OPTIONS</code> being
specified, there are combinations that should not be built.  In that
case, set <code class="code">MULTILIB_EXCEPTIONS</code> to be all of the switch exceptions
in shell case syntax that should not be built.
</p>
<p>For example the ARM processor cannot execute both hardware floating
point instructions and the reduced size THUMB instructions at the same
time, so there is no need to build libraries with both of these
options enabled.  Therefore <code class="code">MULTILIB_EXCEPTIONS</code> is set to:
</p><div class="example smallexample">
<pre class="example-preformatted">*mthumb/*mhard-float*
</pre></div>

</dd>
<dt><a id="index-MULTILIB_005fREQUIRED"></a><span><code class="code">MULTILIB_REQUIRED</code><a class="copiable-link" href="#index-MULTILIB_005fREQUIRED"> &para;</a></span></dt>
<dd><p>Sometimes when there are only a few combinations are required, it would
be a big effort to come up with a <code class="code">MULTILIB_EXCEPTIONS</code> list to
cover all undesired ones.  In such a case, just listing all the required
combinations in <code class="code">MULTILIB_REQUIRED</code> would be more straightforward.
</p>
<p>The way to specify the entries in <code class="code">MULTILIB_REQUIRED</code> is same with
the way used for <code class="code">MULTILIB_EXCEPTIONS</code>, only this time what are
required will be specified.  Suppose there are multiple sets of
<code class="code">MULTILIB_OPTIONS</code> and only two combinations are required, one
for ARMv7-M and one for ARMv7-R with hard floating-point ABI and FPU, the
<code class="code">MULTILIB_REQUIRED</code> can be set to:
</p><div class="example smallexample">
<pre class="example-preformatted"><code class="code">MULTILIB_REQUIRED</code> =  mthumb/march=armv7-m
<code class="code">MULTILIB_REQUIRED</code> += march=armv7-r/mfloat-abi=hard/mfpu=vfpv3-d16
</pre></div>

<p>The <code class="code">MULTILIB_REQUIRED</code> can be used together with
<code class="code">MULTILIB_EXCEPTIONS</code>.  The option combinations generated from
<code class="code">MULTILIB_OPTIONS</code> will be filtered by <code class="code">MULTILIB_EXCEPTIONS</code>
and then by <code class="code">MULTILIB_REQUIRED</code>.
</p>
</dd>
<dt><a id="index-MULTILIB_005fREUSE"></a><span><code class="code">MULTILIB_REUSE</code><a class="copiable-link" href="#index-MULTILIB_005fREUSE"> &para;</a></span></dt>
<dd><p>Sometimes it is desirable to reuse one existing multilib for different
sets of options.  Such kind of reuse can minimize the number of multilib
variants.  And for some targets it is better to reuse an existing multilib
than to fall back to default multilib when there is no corresponding multilib.
This can be done by adding reuse rules to <code class="code">MULTILIB_REUSE</code>.
</p>
<p>A reuse rule is comprised of two parts connected by equality sign.  The left
part is the option set used to build multilib and the right part is the option
set that will reuse this multilib.  Both parts should only use options
specified in <code class="code">MULTILIB_OPTIONS</code> and the equality signs found in options
name should be replaced with periods.  An explicit period in the rule can be
escaped by preceding it with a backslash.  The order of options in the left
part matters and should be same with those specified in
<code class="code">MULTILIB_REQUIRED</code> or aligned with the order in <code class="code">MULTILIB_OPTIONS</code>.
There is no such limitation for options in the right part as we don&rsquo;t build
multilib from them.
</p>
<p><code class="code">MULTILIB_REUSE</code> is different from <code class="code">MULTILIB_MATCHES</code> in that it
sets up relations between two option sets rather than two options.  Here is an
example to demo how we reuse libraries built in Thumb mode for applications built
in ARM mode:
</p><div class="example smallexample">
<pre class="example-preformatted"><code class="code">MULTILIB_REUSE</code> = mthumb/march.armv7-r=marm/march.armv7-r
</pre></div>

<p>Before the advent of <code class="code">MULTILIB_REUSE</code>, GCC select multilib by comparing command
line options with options used to build multilib.  The <code class="code">MULTILIB_REUSE</code> is
complementary to that way.  Only when the original comparison matches nothing it will
work to see if it is OK to reuse some existing multilib.
</p>
</dd>
<dt><a id="index-MULTILIB_005fEXTRA_005fOPTS"></a><span><code class="code">MULTILIB_EXTRA_OPTS</code><a class="copiable-link" href="#index-MULTILIB_005fEXTRA_005fOPTS"> &para;</a></span></dt>
<dd><p>Sometimes it is desirable that when building multiple versions of
<samp class="file">libgcc.a</samp> certain options should always be passed on to the
compiler.  In that case, set <code class="code">MULTILIB_EXTRA_OPTS</code> to be the list
of options to be used for all builds.  If you set this, you should
probably set <code class="code">CRTSTUFF_T_CFLAGS</code> to a dash followed by it.
</p>
</dd>
<dt><a id="index-MULTILIB_005fOSDIRNAMES"></a><span><code class="code">MULTILIB_OSDIRNAMES</code><a class="copiable-link" href="#index-MULTILIB_005fOSDIRNAMES"> &para;</a></span></dt>
<dd><p>If <code class="code">MULTILIB_OPTIONS</code> is used, this variable specifies 
a list of subdirectory names, that are used to modify the search
path depending on the chosen multilib.  Unlike <code class="code">MULTILIB_DIRNAMES</code>,
<code class="code">MULTILIB_OSDIRNAMES</code> describes the multilib directories using
operating systems conventions, and is applied to the directories such as
<code class="code">lib</code> or those in the <code class="env">LIBRARY_PATH</code> environment variable.
The format is either the same as of
<code class="code">MULTILIB_DIRNAMES</code>, or a set of mappings.  When it is the same
as <code class="code">MULTILIB_DIRNAMES</code>, it describes the multilib directories
using operating system conventions, rather than GCC conventions.  When it is a set
of mappings of the form <var class="var">gccdir</var>=<var class="var">osdir</var>, the left side gives
the GCC convention and the right gives the equivalent OS defined
location.  If the <var class="var">osdir</var> part begins with a &lsquo;<samp class="samp">!</samp>&rsquo;,
GCC will not search in the non-multilib directory and use
exclusively the multilib directory.  Otherwise, the compiler will
examine the search path for libraries and crt files twice; the first
time it will add <var class="var">multilib</var> to each directory in the search path,
the second it will not.
</p>
<p>For configurations that support both multilib and multiarch,
<code class="code">MULTILIB_OSDIRNAMES</code> also encodes the multiarch name, thus
subsuming <code class="code">MULTIARCH_DIRNAME</code>.  The multiarch name is appended to
each directory name, separated by a colon (e.g.
&lsquo;<samp class="samp">../lib32:i386-linux-gnu</samp>&rsquo;).
</p>
<p>Each multiarch subdirectory will be searched before the corresponding OS
multilib directory, for example &lsquo;<samp class="samp">/lib/i386-linux-gnu</samp>&rsquo; before
&lsquo;<samp class="samp">/lib/../lib32</samp>&rsquo;.  The multiarch name will also be used to modify the
system header search path, as explained for <code class="code">MULTIARCH_DIRNAME</code>.
</p>
</dd>
<dt><a id="index-MULTIARCH_005fDIRNAME"></a><span><code class="code">MULTIARCH_DIRNAME</code><a class="copiable-link" href="#index-MULTIARCH_005fDIRNAME"> &para;</a></span></dt>
<dd><p>This variable specifies the multiarch name for configurations that are
multiarch-enabled but not multilibbed configurations.
</p>
<p>The multiarch name is used to augment the search path for libraries, crt
files and system header files with additional locations.  The compiler
will add a multiarch subdirectory of the form
<var class="var">prefix</var>/<var class="var">multiarch</var> before each directory in the library and
crt search path.  It will also add two directories
<code class="code">LOCAL_INCLUDE_DIR</code>/<var class="var">multiarch</var> and
<code class="code">NATIVE_SYSTEM_HEADER_DIR</code>/<var class="var">multiarch</var>) to the system header
search path, respectively before <code class="code">LOCAL_INCLUDE_DIR</code> and
<code class="code">NATIVE_SYSTEM_HEADER_DIR</code>.
</p>
<p><code class="code">MULTIARCH_DIRNAME</code> is not used for configurations that support
both multilib and multiarch.  In that case, multiarch names are encoded
in <code class="code">MULTILIB_OSDIRNAMES</code> instead.
</p>
<p>More documentation about multiarch can be found at
<a class="uref" href="https://wiki.debian.org/Multiarch">https://wiki.debian.org/Multiarch</a>.
</p>
</dd>
<dt><a id="index-SPECS"></a><span><code class="code">SPECS</code><a class="copiable-link" href="#index-SPECS"> &para;</a></span></dt>
<dd><p>Unfortunately, setting <code class="code">MULTILIB_EXTRA_OPTS</code> is not enough, since
it does not affect the build of target libraries, at least not the
build of the default multilib.  One possible work-around is to use
<code class="code">DRIVER_SELF_SPECS</code> to bring options from the <samp class="file">specs</samp> file
as if they had been passed in the compiler driver command line.
However, you don&rsquo;t want to be adding these options after the toolchain
is installed, so you can instead tweak the <samp class="file">specs</samp> file that will
be used during the toolchain build, while you still install the
original, built-in <samp class="file">specs</samp>.  The trick is to set <code class="code">SPECS</code> to
some other filename (say <samp class="file">specs.install</samp>), that will then be
created out of the built-in specs, and introduce a <samp class="file">Makefile</samp>
rule to generate the <samp class="file">specs</samp> file that&rsquo;s going to be used at
build time out of your <samp class="file">specs.install</samp>.
</p>
</dd>
<dt><code class="code">T_CFLAGS</code></dt>
<dd><p>These are extra flags to pass to the C compiler.  They are used both
when building GCC, and when compiling things with the just-built GCC.
This variable is deprecated and should not be used.
</p></dd>
</dl>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Host-Fragment.html">Host Makefile Fragments</a>, Up: <a href="Fragments.html">Makefile Fragments</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
